package com.afc.struts.test.persons;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.afc.struts.Action;
import com.afc.struts.test.data.PersonDao;
import com.afc.struts.test.model.Person;
import com.afc.struts.test.person.PersonForm.DefaultPersonForm;

public class PersonsUpdateAction implements Action<PersonsForm>
{
  @Override
  public String execute(PersonsForm anActionForm, HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException
  {
    Person person = PersonDao.getInstance().retrieve(anActionForm.getSelectedPersonId());
    if (person != null)
    {
      aRequest.setAttribute("form", new DefaultPersonForm(person.getId(), person.getFirstName(), person.getLastName(), person.getSize(), person.getBirthday(), person.getBestFriend()));
      return "/pages/personUpdate.jsp";
    }
    return null;
  }
}
